package com.wzx.user.business.shop.controller;

import com.wzx.common.core.controller.AbstractCoreController;
import com.wzx.common.pojo.resp.Result;
import com.wzx.user.pojo.shop.pojo.ShopAddress;
import com.wzx.user.business.shop.service.ShopAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wzx
 * @version 1.0
 * @date 2022/9/7 - 14:43
 * @description 标题
 */
@Api(tags = "地址")
@RestController
@RequestMapping("/shopAddress")
public class ShopAddressController extends AbstractCoreController<ShopAddress> {

    @Autowired
    private ShopAddressService shopAddressService;

    @Autowired
    protected ShopAddressController(ShopAddressService shopAddressService) {
        super(shopAddressService);
        this.shopAddressService = shopAddressService;
    }

    @PostMapping("/getShopAddress")
    @ApiOperation(value = "查询地址信息")
    public Result getShopAddress(@RequestBody ShopAddress shopAddress) throws Exception {
        List<ShopAddress> result = shopAddressService.getShopAddress(shopAddress);
        return Result.ok(result);
    }

    @PostMapping("/addAddress")
    @ApiOperation(value = "新增地址信息")
    public Result addAddress(@RequestBody ShopAddress shopAddress) throws Exception {
        shopAddressService.addAddress(shopAddress);
        return Result.ok();
    }

    @GetMapping("/updateAddressIsDefault")
    @ApiOperation(value = "修改地址默认状态")
    public Result updateAddressIsDefault(Integer addressId, Integer userId) throws Exception {
        shopAddressService.updateAddress(addressId, userId);
        return Result.ok();
    }

    @PostMapping("/updateAddress")
    @ApiOperation(value = "修改地址信息")
    public Result updateAddress(@RequestBody ShopAddress shopAddress) throws Exception {
        shopAddressService.updateAddressObject(shopAddress);
        return Result.ok();
    }
}
